// Copyright 2022 jeff.li. and/or its affiliates.

#include <tbir/pipeline/constant_op.h>

#include <tbir/pipeline/node.h>
#include <tbir/pipeline/tx_session.h>

#include "userdata_mutator.h"

namespace tbir::runtime {

    TBIR_REGISTER_NATIVE_OP(ConstantOp);

    void ConstantOp::Init() {
        MXCHECK(HasAttr("data"));
        data = GetAttr<RTValue>("data");
        UserDataMutator::Mutate(&data, this);
    }

    std::unique_ptr<Symbol> ConstantOp::make_symbol(std::shared_ptr<ConstantOp> op) {
        NodePtr node = Node::Create();
        node->op = op;
        node->name = op->GetName();
        uint64_t node_key = GlobalUniqueIndex::instance()->gen_uniq_signature(node->name);
        std::vector<NodeEntryPtr> nes;
        nes.push_back(std::make_shared<NodeEntry>(node, 0, node_key));
        nes.back()->data = op->data;
        node->outputs = MakeNodeOutputs(nes);
        return std::make_unique<Symbol>(nes, 0);
    }

    RTValue ConstantOp::Process(PyArgs inputs) const {
        CheckArgs(inputs.size(), 0);
        return data;
    }

}  // namespace tbir::runtime
